/**
 * Demonstrates a range of Button options the framework offers out of the box
 */
Ext.define('cloud.view.user.User', {
    extend: 'Ext.navigation.View',
    xtype: 'user',
    requires: ['Ext.List', 'Ext.TitleBar', 'Ext.field.Select', 'Ext.field.Search'],
    config: {
        defaultBackButtonText:'返回',
        items: [
            {
                xtype: 'container',
                layout: 'hbox',
                title: '用户列表',
                items: [
                    {
                        xtype: 'toolbar',
                        ui: 'dark',
                        docked: 'top',
                        items: [
                            {
                                xtype: 'textfield',
                                id: 'search_user',
                                name: 'search_user',
                                placeHolder: '请输入用户名'
                            },
                            {
                                xtype: 'label',
                                style:'text-shadow:none;font-family:"Helvetica Neue";white-space:nowrap;font-size: 16px; color:#606060;padding:0px;margin-left: 100px;',
                                id:'number',
                                html: ' '
                            }
                        ]
                    },
                    {
                        xtype: 'list',
                        flex: 1,
                        store: 'UsersAllFindStore',
                        emptyText: '暂无用户',
                        pressedCls:false,
                        selectedCls:false,
                        cls:'x-list2',
                        onItemDisclosure: true,
                        itemTpl:
                            '<div class="listName">{name}  </div>'+
                                '<div class="listConten">' +
                                '<span>是否停用：{status}</span>' +
                                '</div>',
                        plugins: [
                            {
                                xclass: 'Ext.plugin.PullRefresh',
                                pullRefreshText: '下拉可以更新',
                                releaseRefreshText: '松开开始更新',
                                style:'top:12px',
                                loadingText: '正在刷新……',
                                refreshFn: function (loaded, arguments) {
                                   // loaded.getList().getStore().getProxy().setExtraParam('caid', localStorage.getItem('caid')); //设置proxy参数
                                    loaded.getList().getStore().loadPage(1, {
                                        callback: function (record, operation, success) {
                                            Ext.Viewport.unmask();
                                        }, scope: this });
                                }
                            },
                            {
                                xclass: 'Ext.plugin.ListPaging',
                                loadMoreText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">点击加载更多。。。。</h2>',
                                noMoreRecordsText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">没有更多条记录了</h2>',
                                autoPaging: false //设置为TRUE将自动触发
                            }
                        ],
                        listeners:{
                            initialize:function(){
                                var store=Ext.getStore('UsersAllFindStore')
                                store.load({params: {caid: localStorage.getItem('caid')}});
                                store.getProxy().setExtraParam('caid', localStorage.getItem('caid'));


                                //显示当前用户数量
                                Ext.Ajax.request({
                                    url: GLOBAL.api_url + 'users_number',
                                    params: {caid: localStorage.getItem('caid')},
                                    scope: this,
                                    success: function (response) {
                                        var result = Ext.decode(response.responseText);
                                        if (result.Variables.Result.code == 0) {
                                            var checkboxs = [];
                                            var data = result.Variables.data;
                                            var html = '总用户量：'+data.count+' 一周内的注册用户量：'+data.week+' 当天注册用户量：'+data.day;
                                            Ext.getCmp('number').setHtml(html);
                                        }
                                    }
                                });
                            }
                        }
                    }
                ]
            }
        ]
    }
});